﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Linquid;

namespace LinquidSamples
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			
			InitializeComponent();									
			
			Func<int, int> run = i =>
			{				
				switch (i)
				{
					case 1: 
						ShowDialog(Samples.Sample1);
						break;
					case 2: 
						ShowDialog(Samples.Sample2);
						break;
					case 3: 
						ShowDialog(Calculator.UI);
						break;
					case 4: 
						ShowDialog(Samples.Sample3);
						break;
				}
				return i;
			};						
						
			var choice = 
				from b1 in UIM.Button("Sample1")
				from b2 in UIM.Button("Sample2")
				from b3 in UIM.Button("Calculator")
				from b4 in UIM.Button("Sample3")
				select b1.Const(1).
					   Join(b2.Const(2).
				       Join(b3.Const(3)).
					   Join(b4.Const(4))).
					   Map(run);

			choice.Run(this);						
		}
		
		private void ShowDialog<A>(UI<Source<A>> ui)
		{
			var dialog = new Dialog<A>(ui);
			if (dialog.Show())
			{
				MessageBox.Show("Dialog returned " + dialog.Result);
			}
		}
	}
}
